import echarts from 'echarts'
import '../../../public/static/theme/chalk'

// 初始化图表
export const setEchartOptions = (ref, options) => {
  echarts.init(ref, 'chalk').setOption(options)
}

export const setEcharts = (ref, seriesData = {}) => {
  setEchartOptions(ref, {
    title: {
      show: true,
      text: '▍热销商品销售金额占比统计',
      textStyle: {
        color: 'white',
        fontSize: 30,
        fontWeight: 500
      },
      top: '10%',
      left: '8%'
    },
    legend: {
      show: true,
      top: '18%',
      itemGap: 100,
      icon: 'circle',
      itemWidth: 20,
      itemHeight: 20
    },
    grid: {
      top: '20%',
      left: '10%',
      bottom: '15%'
    },
    tooltip: {
      show: true,
      trigger: 'item',
      triggerOn: 'mousemove',
      formatter: (arg) => {
        console.log(arg)
        // eslint-disable-next-line no-unused-vars
        let str = ''
        const value = arg.data.value
        arg.data.children.map((item) => {
          str +=
            item.name +
            ':' +
            parseInt((item.value / value) * 100) +
            '%' +
            '<br>'
        })
        return arg.data.name + '<br>' + str
      }
    },
    series: [
      {
        type: 'pie',
        radius: '50%',
        data: seriesData,
        label: {
          show: false
        }
      }
    ]
  })
}
